using System.Collections;
using System.Collections.Generic;
using QFramework;
using UnityEngine;

namespace AsterroidX
{
    public class DifficultySystem : AbstractSystem
    {
        public int DifficultyScore=>Mathf.FloorToInt(0.4f.Lerp(mGameModel.RockKillCount.Value,mGameModel.GameSeconds.Value));
        private GameModel mGameModel;
        protected override void OnInit()
        {
            mGameModel = this.GetModel<GameModel>();

            mGameModel.UFOKillCount.Register(count =>
            {
                var time = 10f;
                

                var powerUpCount=this.GetSystem<PowerUpUnlockSystem>().UnlockedPowerUps.Count;

                if(count>=4&&count<6)
                {
                    time = 7.5f;
                }
                else if(count>=6)
                {
                    time = 7;
                }
                else if(count>=3)
                {
                    time = 8;
                }

               
                mGameModel.PowerUpGenerateDuration = time;
            });

            mGameModel.RockKillCount.Register(count =>
            {
                if (DifficultyScore >= 50 && DifficultyScore < 100)
                {
                    mGameModel.MaxRockCount = 8;
                    mGameModel.RockSpeedRate = 0.6f;
                }
                else if (DifficultyScore >= 100 && DifficultyScore < 200)
                {
                    mGameModel.MaxRockCount = 12;
                    mGameModel.RockSpeedRate = 0.8f;
                }
                else if (DifficultyScore >= 200 && DifficultyScore < 300)
                {
                    mGameModel.MaxRockCount = 16;
                    mGameModel.RockSpeedRate = 1f;
                }
                else if (DifficultyScore >= 300 && DifficultyScore   < 500)
                {
                    mGameModel.MaxRockCount = 8;
                    mGameModel.RockSpeedRate = 0.5f;
                    mGameModel.BaseRockSpeed = 2;
                }
                else if (DifficultyScore >= 500 && DifficultyScore < 700)
                {
                    mGameModel.MaxRockCount = 12;
                    mGameModel.RockSpeedRate = 0.7f;

                }
                else if (DifficultyScore >= 700 && DifficultyScore < 900)
                {
                    mGameModel.MaxRockCount = 16;
                    mGameModel.RockSpeedRate = 0.9f;

                }
                else if (DifficultyScore >= 900 && DifficultyScore   < 1200)
                {
                    mGameModel.MaxRockCount = 20;
                    mGameModel.RockSpeedRate = 1.2f;

                }
                else if (DifficultyScore >= 1200 && DifficultyScore < 1500)
                {
                    mGameModel.MaxRockCount = 24;
                    mGameModel.RockSpeedRate = 1.5f;

                }
                else if (DifficultyScore >= 1500 && DifficultyScore < 1800)
                {
                    mGameModel.MaxRockCount = 28;
                    mGameModel.RockSpeedRate = 1.8f;

                }
                else if (DifficultyScore     >= 1800 && DifficultyScore < 2100)
                {
                    mGameModel.MaxRockCount = 12;
                    mGameModel.RockSpeedRate = 2f;

                }
                else if (DifficultyScore >= 2100 && DifficultyScore < 2500)
                {
                    mGameModel.MaxRockCount = 16;
                    mGameModel.RockSpeedRate = 0.5f;
                    mGameModel.BaseRockSpeed = 3;

                }
                else if (DifficultyScore >= 2500 && DifficultyScore < 2900)
                {
                    mGameModel.MaxRockCount = 20;
                    mGameModel.RockSpeedRate = 1f;

                }
                else if (DifficultyScore     >= 2900 && DifficultyScore < 3300)
                {
                    mGameModel.MaxRockCount = 24;
                    mGameModel.RockSpeedRate = 1.5f;

                }

                else if (DifficultyScore >= 3300 && DifficultyScore < 3700)
                {
                    mGameModel.MaxRockCount = 28;
                    mGameModel.RockSpeedRate = 2f;

                }
                else if (DifficultyScore >= 3700 && DifficultyScore < 4200)
                {
                    mGameModel.MaxRockCount = 32;
                    mGameModel.RockSpeedRate = 2.5f;

                }
                else if (DifficultyScore >= 4200 && DifficultyScore < 5000)
                {
                    mGameModel.MaxRockCount = 36;
                    mGameModel.RockSpeedRate = 3;

                }
                else if (count >= 5000)
                {
                    if (count % 1000 == 0)
                    {
                        var k = count / 1000;

                        if (k % 4 == 0)
                        {
                            mGameModel.BaseRockSpeed++;
                        }
                        mGameModel.MaxRockCount = 12 + k % 3 * 12;

                        mGameModel.RockSpeedRate = k % 5;
                    }
                }
            });

        }
    }
}
